Skip to content

Implementation Edit to Bogo Sort in Javascript #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 27, 2018
Merged

Implementation Edit to Bogo Sort in Javascript #291

merged 3 commits into from
Aug 27, 2018

Conversation

Wesley-Arrington
Copy link
Contributor

Added main() to code so that it can be run as is

- Added main()
- bogoSort() now returns the sorted array
@Gathros Gathros added the Implementation Edit This provides an edit to an algorithm implementation. (Code and maybe md files are edited.) label Jul 22, 2018
Copy link
Contributor

@Butt4cak3 Butt4cak3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JS version was missing a main function. Good catch. But I can't merge this in its current state.

@@ -12,6 +12,7 @@ function bogoSort(arr) {
while (!isSorted(arr)) {
shuffle(arr);
}
return arr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function doesn't have to return the array, because it's passed by reference anyway.


function main() {
var testArray = [4,5,123,24,34,-5];
print(bogoSort(testArray));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print does not exist in JavaScript. And because you don't need return arr above, you'd have to output it like this:

bogoSort(testArray);
console.log(testArray);

@@ -22,3 +23,10 @@ function shuffle(arr) {
arr[r] = tmp;
}
}

function main() {
var testArray = [4,5,123,24,34,-5];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly to the other PR: JS files should be indented with 2 spaces and use const for non-chaning variables (and let for mutable ones). var is pretty much legacy at this point. Also, there should be spaces after the commas in the array initialization ([1, 2, 3] instead of [1,2,3]).

@Wesley-Arrington
Copy link
Contributor Author

Sorry for all the mistakes in my Javascript PRs. Clearly I'm not super comfortable with Javascript. Thanks for helping me out with my PRs and I think I've fixed both Javascript PRs.

@@ -25,8 +24,9 @@ function shuffle(arr) {
}

function main() {
var testArray = [4,5,123,24,34,-5];
print(bogoSort(testArray));
let testArray = [4, 5, 123, 24, 34, -5];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't change, it should be const. Same in the other PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry about that. I made a commit to correct the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this not change? It's being sorted later.

@june128
Copy link
Member

june128 commented Aug 3, 2018

@Butt4cak3 @Gustorn How is the state of this PR?

@PudottaPommin
Copy link
Member

Looks fine with changes requested

@@ -22,3 +22,11 @@ function shuffle(arr) {
arr[r] = tmp;
}
}

function main() {
const testArray = [4, 5, 123, 24, 34, -5];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know JS too well, but if you declare testArray and const can you actually modify it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you can not reassign this. but you can add/remove/reorder elements in array like this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty silly ^^

@jiegillet jiegillet dismissed Butt4cak3’s stale review August 27, 2018 00:48

Changes were made as requested, Butt4cak3 was away

Copy link
Member

@jiegillet jiegillet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes were made as requested, thank you!

@jiegillet jiegillet merged commit b6e7c19 into algorithm-archivists:master Aug 27, 2018
@Wesley-Arrington Wesley-Arrington deleted the javascriptBogo branch September 10, 2018 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation Edit This provides an edit to an algorithm implementation. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants